package com.example.springboot_code_read.beanDefinitionHolder;

import com.example.springboot_code_read.bean.MyBean;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;

public class BeanDefinitionHolderTest {

    public static void main(String[] args) {

        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(MyBean.class);
        beanDefinition.getPropertyValues().add("id", "1");
        beanDefinition.getPropertyValues().add("name", "xiaomi");

        String beanName = "myBean";
        String[] aliases = {"myBean1", "myBean2"};
        BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(beanDefinition, beanName, aliases);
        BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, beanFactory);

        System.out.println("myBean=" + beanFactory.getBean(beanName));
        System.out.println("myBean1=" + beanFactory.getBean("myBean1"));
        System.out.println("myBean2=" + beanFactory.getBean("myBean2"));


    }

}
